using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace DrawImageSample
{
    public class Resources : IDisposable
    {
        private static List<Pen> sPens = new List<Pen>();

        public static Pen GetPen(Color pColor, float pWidth)
        {
            foreach (Pen pen in sPens)
            {
                if ((pen.Color == pColor) && (pen.Width == pWidth))
                {
                    return pen;
                }
            }

            Pen newPen = new Pen(pColor, pWidth);
            sPens.Add(newPen);
            newPen.StartCap = LineCap.Round;
            newPen.EndCap = LineCap.Round;
            newPen.DashCap = DashCap.Round;

            return newPen;
        }

        public static Graphics GetGraphics(Graphics pGraphics)
        {
            //Console.WriteLine("[B]Graphic: (PageScale={0}) (PageUnit={1})", pGraphics.PageScale.ToString(), pGraphics.PageUnit.ToString());

            pGraphics.PageScale = 1.0f;
            pGraphics.PageUnit = GraphicsUnit.Display;
            pGraphics.SmoothingMode = SmoothingMode.AntiAlias;

            //Console.WriteLine("[A]Graphic: (PageScale={0}) (PageUnit={1})", pGraphics.PageScale.ToString(), pGraphics.PageUnit.ToString());

            return pGraphics;
        }

        public void Dispose()
        {
            foreach (Pen pen in sPens)
            {
                pen.Dispose();
            }
            sPens.Clear();
        }
    }
}
